package com.eBook.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eBook.entity.Comment;
import com.eBook.service.CommentService;

@Controller
@RequestMapping(value = "/comment")
public class CommentController {
	@Autowired
	private CommentService cService;
	//必须含有参数bookId。
	@RequestMapping(value = "/{bookId}")
	@ResponseBody
	public List<Comment> getAllCommentsByBookId(@PathVariable("bookId")int bookId){
		return cService.findAllCommentsByBookId(bookId);
	}
	//必须含有参数 bookId,userId,content
	@RequestMapping(value = "/",method = RequestMethod.POST)
	@ResponseBody
	public String addComment(int bookId,int userId,String content){
		cService.addComment(bookId, userId, content);
		return "Ok";
	}
}
